package com.ys.shop.control;

import com.ys.shop.dao.GoodDAOImp;
import com.ys.shop.dao.IDAO;
import com.ys.shop.vo.Product;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet(name = "Product-viewServlet")
public class ProductviewServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //1、获取商品ID
        int id=Integer.parseInt(request.getParameter("id"));

//        String s=3+"";
        //2、取数据
        IDAO idao=new GoodDAOImp();
        Product product=((GoodDAOImp) idao).getGoodByID(id);
        //3、在两个页面之间传递数据
        request.setAttribute("productinfo",product);
        //4、转到显示商品详情的页面去.30

        request.getRequestDispatcher("Product-view.jsp").forward(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }
}
